<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	/**
	 * _config 
	 * 
	 * @var Zend_Config
	 * @access private
	 */
	private $_config = null;
	/**
	 * _db 
	 * 
	 * @var Zend_Config
	 * @access private
	 */
	private $_db = null;
	/**
	 * _initView 
	 *
	 * 构造 _initView
	 * 
	 * @access public
	 * @return void
	 */
	protected function _initView() {
		$this->_config = new Zend_Config_Ini ( CONFIG_FILE, 'staging' );
		require_once $this->_config->smarty->class_path;
		
		$smarty = new Smarty ( );
		$smarty->left_delimiter = $this->_config->smarty->left_delimiter;
		$smarty->right_delimiter = $this->_config->smarty->right_delimiter;
		$smarty->template_dir = APPLICATION_PATH . '/' . $this->_config->smarty->template_dir;
		$smarty->compile_dir = PROJECT_ROOT . '/' . $this->_config->smarty->compile_dir;
		$smarty->cache_dir = PROJECT_ROOT . '/' . $this->_config->smarty->cache_dir;
		$smarty->cache_lifetime = $this->_config->smarty->cache_lifetime;
		$smarty->caching = $this->_config->smarty->caching;

		$smarty->debugging = $this->_config->smarty->debugging;
		$smarty->error_reporting = $this->_config->smarty->error_reporting;
		$smarty->force_compile = $this->_config->smarty->force_compile;
		
		Zend_Registry::set ( 'smarty', $smarty );
		
	//$view = new Zend_View();
	//$view->addHelperPath(APPLICATION_PATH.'/views/helpers', 'My_View_Helper');
	//$loader = new Zend_Loader_PluginLoader();
	//$loader->addPrefixPath('My_View_Helper', APPLICATION_PATH.'/views/helpers');   
	}
	
	/**
	 * buildSession 
	 *
	 * 构造 session
	 * 
	 * @access public
	 * @return void
	 */
	protected function _initSession() {
		$sessionConfig = $this->_config->session->toArray ();
		//print_r($sessionConfig);
		$sessionConfig['save_path']=PROJECT_ROOT . '/' .$sessionConfig['save_path'];
		Zend_Session::setOptions ( $sessionConfig );
	}
	
/**
 * _initDB 
 *
 * 构造 _initDB
 * 
 * @access public
 * @return void
 */
/*
	public function _initDB() {
		$dbConfig = $this->_config->db->toArray ();
		$this->_dbAdapter = Zend_Db::factory ( $this->_config->$name->adapter, $this->_config->$name->toArray () );
		$this->_dbAdapter->getProfiler ()->setEnabled ( $this->_config->$name->profiler );
		// 设置编码，临时使用，当 Zend Framework 的 charset 可用时去除。
		$this->_dbAdapter->query ( 'set names ' . $this->_config->$name->config->charset );
		//
		Zend_Registry::set ( 'dbAdapter', $this->_dbAdapter );
		
		$options = $options ['db'];
		
		$resources = $this->getPluginResource ( 'db' );
		$db = $resources->getDbAdapter ();
		Zend_Db_Table::setDefaultAdapter ( $db );
		Zend_Registry::set ( 'dbAdapter', $db );
		Zend_Registry::set ( 'dbprefix', $options ['params'] ['prefix'] );
	
	}
	*/
//同理设置多语言(前期学习可以不用..可以去掉)
/*
    protected function _initTranslate()
    {
 
        $options = $this->getOption('resources');
        $options = $options['translate'];
        if (!isset($options['data'])) {
            throw new Zend_Application_Resource_Exception('对不起,没有找到语言文件!');
        }
        $adapter = isset($options['adapter']) ? $options['adapter'] : Zend_Translate::AN_ARRAY;
        $session = new Zend_Session_Namespace('locale');
        if ($session->locale) {
           $locale = $session->locale;
        }else {
            $locale  = isset($options['locale'])  
                         ? $options['locale']
                         : null;
        }
        $data = '';
        if (isset($options['data'][$locale])) {
            $data = $options['data'][$locale];
        }
        $translateOptions = isset($options['options']) 
                                     ? $options['options']
                                     : array();
	Zend_Registry::set('Zend_Translate', $translate);
 
        return $translate;
 
    }
    */

}

